package com.fwtai.api.controller;

import com.fwtai.config.ConfigFile;
import com.fwtai.entity.ReqPage;
import com.fwtai.service.api.ApiStoreService;
import com.fwtai.tool.ToolClient;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 门店店主|路由层[api]
 * @作者 田应平
 * @版本 v1.0
 * @QQ号码 444141300
 * @创建日期 2023-04-04 17:45:50
 * @官网 <url>http://www.fwtai.com</url>
*/
@RestController
@Api(tags = "门店店主",description = "token选填")
@RequestMapping(ConfigFile.guest_v10 +"store")
public class StoreController{

  private final ApiStoreService apiStoreService;

  public StoreController(final ApiStoreService apiStoreService){
    this.apiStoreService = apiStoreService;
  }

  /**添加*/
  @ApiOperation(value = "门店申请", notes = "新建|新增|添加操作,bean实体form表单方式非json格式提交")
  @ApiImplicitParams({
    @ApiImplicitParam(name = "name", value = "门店名称,限制长度128个", dataType = "String", paramType = "query", required = true),
    @ApiImplicitParam(name = "img_front", value = "身份证的人像面,json格式的数据", dataType = "String", paramType = "query", required = true),
    @ApiImplicitParam(name = "img_reverse", value = "身份证的国徽面,json格式的数据", dataType = "String", paramType = "query", required = true),
    @ApiImplicitParam(name = "protocol", value = "门店申请时的协议图片,json格式的数据", dataType = "String", paramType = "query", required = true),
    @ApiImplicitParam(name = "license", value = "营业执照,json格式的数据", dataType = "String", paramType = "query", required = true),
    @ApiImplicitParam(name = "thumbnail", value = "门店缩略图,限制1张，显示格式为.jpg|.jpeg|.png", dataType = "String", paramType = "query", required = false),
    @ApiImplicitParam(name = "pictures", value = "门店环境（限制5张，显示格式为.jpg|.jpeg|.png）,文件格式为: pictures1:文件1,pictures2:文件2,pictures3:文件3...", dataType = "String", paramType = "query", required = false),
    @ApiImplicitParam(name = "contacts", value = "门店联系人,限制长度40个", dataType = "String", paramType = "query", required = true),
    @ApiImplicitParam(name = "telephone", value = "门店联系电话,限制长度20个", dataType = "String", paramType = "query", required = true),
    @ApiImplicitParam(name = "longitude", value = "门店的经度,限制长度40个", dataType = "String", paramType = "query", required = false),
    @ApiImplicitParam(name = "latitude", value = "门店的纬度,限制长度40个", dataType = "String", paramType = "query", required = false),
    @ApiImplicitParam(name = "time_frame", value = "营业时间（格式：09:00-22:00）,限制长度20个", dataType = "String", paramType = "query", required = true),
    @ApiImplicitParam(name = "province_id", value = "省主键kid,限制长度20个", dataType = "long", paramType = "query", required = true),
    @ApiImplicitParam(name = "province_name", value = "省名称,限制长度40个", dataType = "String", paramType = "query", required = true),
    @ApiImplicitParam(name = "city_id", value = "市主键kid,限制长度20个", dataType = "long", paramType = "query", required = true),
    @ApiImplicitParam(name = "city_name", value = "市名称,限制长度20个", dataType = "String", paramType = "query", required = true),
    @ApiImplicitParam(name = "county_id", value = "区县kid,限制长度20个", dataType = "long", paramType = "query", required = true),
    @ApiImplicitParam(name = "county_name", value = "区县名称,限制长度20个", dataType = "String", paramType = "query", required = true),
    @ApiImplicitParam(name = "address", value = "地址,限制长度128个", dataType = "String", paramType = "query", required = true),
    @ApiImplicitParam(name = "code", value = "推荐人的邀请码", dataType = "String", paramType = "query", required = true),
    @ApiImplicitParam(name = "introduce", value = "门店介绍,限制长度921600000个", dataType = "String", paramType = "query", required = true)
  })
  @PostMapping("/add")
  public void add(
    final HttpServletRequest request,final HttpServletResponse response){
    ToolClient.responseJson(apiStoreService.add(request),response);
  }

  /**编辑*/
  @ApiOperation(value = "编辑门店", notes = "通过主键kid编辑|修改数据,字段的参照表结构，主键的字段可能不是id或kid,请参考表结构")
  @ApiImplicitParams({
    @ApiImplicitParam(name = "kid", value = "被修改的主键值,其余的参照表结构", dataType = "String", paramType = "query", required = true),
    @ApiImplicitParam(name = "name", value = "门店名称,限制长度128个", dataType = "String", paramType = "query", required = true),
    @ApiImplicitParam(name = "img_front", value = "身份证的人像面,json格式的数据", dataType = "String", paramType = "query", required = true),
    @ApiImplicitParam(name = "img_reverse", value = "身份证的国徽面,json格式的数据", dataType = "String", paramType = "query", required = true),
    @ApiImplicitParam(name = "protocol", value = "门店申请时的协议图片,json格式的数据", dataType = "String", paramType = "query", required = true),
    @ApiImplicitParam(name = "license", value = "营业执照,json格式的数据", dataType = "String", paramType = "query", required = true),
    @ApiImplicitParam(name = "thumbnail", value = "门店缩略图,限制1张，显示格式为.jpg|.jpeg|.png", dataType = "String", paramType = "query", required = false),
    @ApiImplicitParam(name = "pictures", value = "门店环境（限制5张，显示格式为.jpg|.jpeg|.png）,文件格式为: pictures1:文件1,pictures2:文件2,pictures3:文件3...", dataType = "String", paramType = "query", required = false),
    @ApiImplicitParam(name = "contacts", value = "门店联系人,限制长度40个", dataType = "String", paramType = "query", required = true),
    @ApiImplicitParam(name = "telephone", value = "门店联系电话,限制长度20个", dataType = "String", paramType = "query", required = true),
    @ApiImplicitParam(name = "longitude", value = "门店的经度,限制长度40个", dataType = "String", paramType = "query", required = false),
    @ApiImplicitParam(name = "latitude", value = "门店的纬度,限制长度40个", dataType = "String", paramType = "query", required = false),
    @ApiImplicitParam(name = "time_frame", value = "营业时间（格式：09:00-22:00）,限制长度20个", dataType = "String", paramType = "query", required = true),
    @ApiImplicitParam(name = "province_id", value = "省主键kid,限制长度20个", dataType = "long", paramType = "query", required = true),
    @ApiImplicitParam(name = "province_name", value = "省名称,限制长度40个", dataType = "String", paramType = "query", required = true),
    @ApiImplicitParam(name = "city_id", value = "市主键kid,限制长度20个", dataType = "long", paramType = "query", required = true),
    @ApiImplicitParam(name = "city_name", value = "市名称,限制长度20个", dataType = "String", paramType = "query", required = true),
    @ApiImplicitParam(name = "county_id", value = "区县kid,限制长度20个", dataType = "long", paramType = "query", required = true),
    @ApiImplicitParam(name = "county_name", value = "区县名称,限制长度20个", dataType = "String", paramType = "query", required = true),
    @ApiImplicitParam(name = "address", value = "地址,限制长度128个", dataType = "String", paramType = "query", required = true),
    @ApiImplicitParam(name = "introduce", value = "门店介绍,限制长度921600000个", dataType = "String", paramType = "query", required = true)
  })
  @PostMapping("/edit")
  public void edit(
    final HttpServletRequest request,final HttpServletResponse response){
    ToolClient.responseJson(apiStoreService.edit(request),response);
  }

  /**补充签署协议入口*/
  @ApiOperation(value = "补充签署协议入口", notes = "通过主键kid编辑|修改数据,补充签署协议入口")
  @ApiImplicitParams({
    @ApiImplicitParam(name = "kid", value = "被修改的kid主键值,其余的参照表结构", dataType = "long", paramType = "query", required = true),
    @ApiImplicitParam(name = "protocol", value = "门店申请时的协议图片,json格式的数据", dataType = "String", paramType = "query", required = true)
  })
  @PostMapping("/editProtocol")
  public void editProtocol(final Long kid,final String protocol,final HttpServletResponse response){
    ToolClient.responseJson(apiStoreService.editProtocol(kid,protocol),response);
  }

  /**根据主键kid查询对应的数据*/
  @ApiOperation(value = "获取单条的门店管理详细信息", notes = "通过主键kid获取门店管理详细信息")
  @ApiImplicitParam(name = "id", value = "被查看的kid", dataType = "String", paramType = "query", required = true)
  @GetMapping("/queryById")
  public void queryById(final Long id,final HttpServletResponse response){
    ToolClient.responseJson(apiStoreService.queryById(id),response);
  }

  /**根据主键kid查询对应的数据*/
  @ApiOperation(value = "获取区级代理的商品列表", notes = "通过主键kid获取门店管理详细信息")
  @GetMapping("/getAreaGoods")
  public void getAreaGoods(final HttpServletResponse response){
    ToolClient.responseJson(apiStoreService.getAreaGoods(),response);
  }

  /**获取分页数据,请勿删除ReqPage否则swagger不显示参数*/
  @ApiOperation(value = "获取门店管理分页数据,默认仅含数据不含总记录数总条数", notes = "其参数是搜索过滤条件;排序的key为column值为返回的字段，排序关键字的key为order,其值可选正序ASC|倒序DESC<br/>注意调用端需要判断每次请求返回的条数是否小于每页大小或返回的code=201而停止下一次请求")
  @GetMapping("/listDataPage")
  @ApiImplicitParams({
    @ApiImplicitParam(name = "longitude", value = "用户所在位置经度", dataType = "String", paramType = "query", required = false),
    @ApiImplicitParam(name = "latitude", value = "用户所在位置纬度", dataType = "String", paramType = "query", required = false),
    @ApiImplicitParam(name = "maxLon", value = "经度范围（最大值）", dataType = "String", paramType = "query", required = false),
    @ApiImplicitParam(name = "minLon", value = "经度范围（最小值）", dataType = "String", paramType = "query", required = false),
    @ApiImplicitParam(name = "maxLat", value = "纬度范围（最大值）", dataType = "String", paramType = "query", required = false),
    @ApiImplicitParam(name = "minLat", value = "纬度范围（最小值）", dataType = "String", paramType = "query", required = false),
    @ApiImplicitParam(name = "storeName", value = "门店名称", dataType = "String", paramType = "String", required = false)
  })
  public void listDataPage(final ReqPage reqPage,final HttpServletRequest request,final HttpServletResponse response){
    ToolClient.responseJson(apiStoreService.listData(request),response);
  }

  /**根据主键kid查询对应的数据*/
  @ApiOperation(value = "获取邀请我的区级代理的商品列表", notes = "通过主键kid获取门店管理详细信息")
  @GetMapping("/getInviteAreaGoods")
  public void getInviteAreaGoods(final HttpServletResponse response){
    ToolClient.responseJson(apiStoreService.getInviteAreaGoods(),response);
  }

  /**根据主键kid查询对应的数据*/
  @ApiOperation(value = "获取我的门店kid", notes = "我的门店kid")
  @GetMapping("/queryMyStoreId")
  public void queryMyStoreId(final HttpServletResponse response){
    ToolClient.responseJson(apiStoreService.queryMyStoreId(),response);
  }

  /**根据经纬度查询距离用户最近的门店*/
  @ApiOperation(value = "首页获取最近门店", notes = "通过前端传递的经纬度距离用户最近的门店")
  @GetMapping("/queryNearestStore")
  @ApiImplicitParams({
    @ApiImplicitParam(name = "longitude", value = "经度", dataType = "String", paramType = "String", required = true),
    @ApiImplicitParam(name = "latitude", value = "纬度", dataType = "String", paramType = "String", required = true)
  })
  public void queryNearestStore(final HttpServletRequest request,final HttpServletResponse response){
    ToolClient.responseJson(apiStoreService.queryNearestStore(request),response);
  }

  /**根据区域Id查询区级代理*/
  @ApiOperation(value = "查询区域代理", notes = "根据区域Id查询区级代理")
  @GetMapping("/queryAreaAgency")
  @ApiImplicitParam(name = "areaId", value = "区域Id", dataType = "String", paramType = "String", required = true)
  public void queryAreaAgency(final String areaId,final HttpServletResponse response){
    ToolClient.responseJson(apiStoreService.queryAreaAgency(areaId),response);
  }

  @ApiOperation(value = "更新编辑门店头像,token必填", notes = "更新编辑门店头像")
  @ApiImplicitParams({
    @ApiImplicitParam(name = "portrait", value = "照片头像",dataType ="图片文件",allowMultiple = true, paramType = "query", required = true)
  })
  @PostMapping("/editPortrait")
  public void editPortrait(final HttpServletRequest request,final HttpServletResponse response){
    ToolClient.responseJson(apiStoreService.editStoreThumbnail(request),response);
  }
}